/**
 * Created by chentao on 2015/8/13.
 */

var Admin;
if (!Admin) {
    Admin = {}
}

/**
 * 显示状态
 * @param value
 * @param row
 * @param index
 * @returns {string}
 */
Admin.showEnable = function (value, row, index) {

    if (row.id != 1) {
        if (value == 1) {
            return [
                '<a href="javascript:void(0)" onclick="mergeEnable(' + 0 + ',' + row.id + ')"><span style="color: green">可用</span></a>'
            ].join('');
        } else {
            return [
                '<a href="javascript:void(0)" onclick="mergeEnable(' + 1 + ',' + row.id + ')"><span style="color: red">不可用</span></a>'
            ].join('');
        }
    }
}

/**
 * 修改用户状态
 * @param enable
 * @param id
 */
var mergeEnable = function (enable, id) {
    comment.post("/web/admin/mergeEnable", {id: id, enable: enable}, null, function (data) {
        if (data.res.code == 40000) {
            comment.refresh();
        } else {
            hint("操作失败");
        }
    });
    return false;
}

/**
 * 点击添加用户按钮
 */
bindClick("#addAdmin", function () {
    showModel("addAdmin-div", function () {

    });
});

//提交表单后回调
var saveAdmin = function (data) {
    var d = JSON.parse(data);
    console.log(d);
}

bindClick("#deleteAdmin", function () {
    comment.showOperationTips("确定删除吗？", function () {
        var rowid = $("#id").val();
        $.post($().AbsUrlParse('/web/ensadmin/delete'), {
            id: rowid
        }, function (data) {
            if (data.state == true) {
                if (data.res.code == 40000) {
                    hint("删除成功");
                    comment.refresh();
                    closeModel("editAdmin-div");
                } else {
                    hint(data.res.msg);
                }
            } else {
                hint(data.msg);
            }
        });
    });
});


Admin.editAdminShow = function(row,formid){
    setRowToFrm(formid, row);
    return false;
}

//下面是进行的分组的操作

bindClick("#fenzu",function(){
    comment.showOperationTips("确定给评委发送进行分组吗",function(){
        $.post($().AbsUrlParse("/web/ensadmin/fenzu"),{
                "roleId":13
            },function(data){
                if (data.state == true) {
                    if (data.res.code == 40000) {
                        hint("已经成功给评委进行了分组");
                        var table = $('#table');
                        table.bootstrapTable('refresh');
                    } else {
                        hint(data.res.msg);
                    }
                } else {
                    hint(data.msg);
                }
         });
    });
});

//下面给机构评委进行发送邮件与短信
bindClick("#DuanXinYouJian",function(){
    comment.showOperationTips("确定给全部评委发送短信及邮件吗？",function(){
        $.post($().AbsUrlParse("/web/ensadmin/duanXinYouJian"),{
            roleId:13
        },function(data){
            if(data.state==true){
                if(data.res.code==40000){
                    hint("已成功给评委发送了邮件与短信");
                }else{
                    hint(data.res.msg);
                }
            }else{
                hint(data.msg);
            }
        });
    });
});


